<template>
	<view class="nickname bg min100">
		<view class="nickname-name color-c2 size-28 pl-30 pt-20 pb-20">给自己起个喜欢的名称</view>
		<view class="nickname-ipt flex plr-30">
			<input type="text" v-model="info.nick_name" placeholder="请输入昵称">
			<image src="/static/icon-close.png" mode="" v-if="info.nick_name" @click="info.nick_name = ''"></image>
		</view>
		<view class="mt-45 plr-30">
			<u-button class="nickname-btn" hover-class="none" @click="submit">提交</u-button>
		</view>
	</view>
</template>

<script>
	export default {
		
		data() {
			return {
				info: {}
			};
		},
		methods: {
			submit() {
				if (!this.info.nick_name) return uni.showToast({
					title: '请输入昵称',
					icon: 'none'
				})
				this.$http(
					'api/user/editUserInfo', this.info,
					'POST'
				).then(res => {
					uni.showToast({
						title: '修改成功!',
					})
					setTimeout(() => {
						uni.navigateBack()
					}, 800)
				})
			},
			getUserInfo() {
				this.$http('api/user/userInfo').then(res => {
					this.info = res
				})
			}
		},
		onLoad() {
			this.getUserInfo()
		}
	}
</script>

<style lang="scss">
	.nickname-ipt {
		height: 100rpx;
		background: #fff;

		input {
			flex: 1;
			font-size: 30rpx;
			color: #282828;
		}

		image {
			width: 46rpx;
			height: 46rpx;
		}
	}

	.nickname-btn {
		color: #FFFFFF;
		font-size: 30rpx;
		height: 88rpx !important;
		background: linear-gradient(90deg, #EEA634, #DE2D32);
		border-radius: 44rpx;

		&::after {
			border: none;
		}
	}
</style>
